using MediatR;
using SumerCoreDevOps.Application.Users.Commands;
using SumerCoreDevOps.Infrastructure.Identity;

namespace SumerCoreDevOps.Application.Users.Handlers;

/// <summary>
/// 修改密码命令处理器
/// </summary>
public class ChangePasswordCommandHandler : IRequestHandler<ChangePasswordCommand>
{
    private readonly UserManager _userManager;

    public ChangePasswordCommandHandler(UserManager userManager)
    {
        _userManager = userManager;
    }

    public async Task Handle(ChangePasswordCommand request, CancellationToken cancellationToken)
    {
        await _userManager.ChangePasswordAsync(
            request.UserId,
            request.OldPassword,
            request.NewPassword
        );
    }
}
